package pers.qianyu.month_202103.date_20210306.qixinan;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.handleInput();
        if (main.cnt == 0 || main.cnt == 1) {
            System.out.println(0);
            return;
        }
        main.dfs();
        System.out.println(main.res);
    }

    private void handleInput() {
        Scanner sc = new Scanner(System.in);
        cnt = Integer.parseInt(sc.nextLine());
        String[] s = sc.nextLine().split(" ");
        start = Integer.parseInt(s[0]);
        end = Integer.parseInt(s[1]);
        visited = new boolean[cnt];
        for (int i = 0; i < cnt; i++) {
            map.put(i, new HashSet<>());
        }
        while (sc.hasNextLine()) {
            String line = sc.nextLine();
            String[] s2 = line.split(" ");
            int i = Integer.parseInt(s2[0]);
            int j = Integer.parseInt(s2[1]);
            int len = Integer.parseInt(s2[2]);
            if (i == 0 && j == 0 && len == 0) break;
            if (i < 0 || i >= cnt || j < 0 || j >= cnt) continue;
            map.putIfAbsent(i, new HashSet<>());
            map.putIfAbsent(j, new HashSet<>());
            map.get(i).add(new Edge(len, j));
            map.get(j).add(new Edge(len, i));
        }
    }

    private void dfs() {
        visited[0] = true;
        recur(start, 0);
    }

    private void recur(int cur, int sum) {
        if (cur >= cnt) return;
        if (cur == end) {
            res = Math.min(sum, res);
            return;
        }
        if (!map.containsKey(cur)) return;
        Set<Edge> edges = map.get(cur);
        for (Edge edge : edges) {
            if (visited[edge.node]) continue;
            visited[edge.node] = true;
            recur(edge.node, sum + edge.len);
            visited[edge.node] = false;
        }
    }

    private int res = Integer.MAX_VALUE;
    private int cnt, start, end;
    private boolean[] visited;
    private HashMap<Integer, Set<Edge>> map = new HashMap<>();

    private static class Edge {
        private int len, node;

        public Edge(int len, int node) {
            this.len = len;
            this.node = node;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Edge edge = (Edge) o;

            if (len != edge.len) return false;
            return node == edge.node;
        }

        @Override
        public int hashCode() {
            int result = len;
            result = 31 * result + node;
            return result;
        }
    }
}
